<?php

class Application_Form_InternshipApplication extends Zend_Form
{

    public function init()
    {
    
		$longTextLenValid = new Zend_Validate_StringLength(array('max' => 1000));
		$gpavalid = new Zend_Validate_Regex(array('pattern' => '/\d\.\d\d?$/'));
		
		$this->setMethod('post');
		$this->addElement('select','year',array(
	    	'label' => 'Academic Year:',
	    	'MultiOptions' => array('1'=>'First Year','2'=>'Sophmore','3'=>'Junior', '4'=>'Senior'),
	    	'filters' => array('StringTrim'),
	    	'required' => True,
	    	)
		);

		$this->addElement('text','gpa',array(
	    	'label' => 'Current GPA:',
	    	'filters' => array('StringTrim'),
	   		'validators' => array($gpavalid),
	    	'required' => True,
	    	)
		);

		$this->addElement('radio','transport',array(
	    	'label' => 'Do you have access to transportation (ie. a car)?',
	    	'multiOptions' => array('y'=>'Yes','n'=>'No'),
	   		'separator'=>'',
	    	'required' => True,
	    	)
		);

		$this->addElement('textarea','experience',array(
	    	'label' => 'Have you had any prior experience with APPLES Service-Learning Program? If so, please specify below. ',
	    	'filters' => array('StringTrim'),
	    	'validators'=>array($longTextLenValid),
	    	'required' => True,
			)
		);

		$this->addElement('textarea','issue',array(
	    	'label' => 'Describe a social issue that interests you and explain why. Please add any work you have done concerning this social issue.',
	    	'filters' => array('StringTrim'),
	    	'validators'=>array($longTextLenValid),
	    	'required' => True,
			)
		);

		$this->addElement('textarea','coursework',array(
	    	'label' => 'Describe Your Relevant Coursework:',
	    	'validators'=>array($longTextLenValid),
	    	'filters' => array('StringTrim'),
	    	'required' => True,
			)
		);
		
		$this->addElement('select','pref1',array(
	    	'label' => 'Select First Placement Preference:',
	    	'filters' => array('StringTrim'),
	    	'required' => True,
	    	'multiOptions' => $this->getPositions()
			)
		);
		$this->addElement('textarea','pref1text',array(
	    	'label' => 'Please describe your interest and qualification(s) for your first internship site:',
	    	'filters' => array('StringTrim'),
	    	'validators'=>array($longTextLenValid),
	    	'required' => True,
			)
		);
		
		$this->addElement('select','pref2',array(
	    	'label' => 'Select Second Placement Preference:',
	    	'filters' => array('StringTrim'),
	    	'required' => True,
	    	'multiOptions' => $this->getPositions()
			)
		);
		$this->addElement('textarea','pref2text',array(
	    	'label' => 'Please describe your interest and qualification(s) for your third internship site:',
	    	'filters' => array('StringTrim'),
	    	'validators'=>array($longTextLenValid),
	    	'required' => True,
			)
		);
		
		$this->addElement('select','pref3',array(
	    	'label' => 'Select Third Placement Preference:',
	    	'filters' => array('StringTrim'),
	    	'required' => True,
	    	'multiOptions' => $this->getPositions()
			)
		);
		$this->addElement('textarea','pref3text',array(
	    	'label' => 'Please describe your interest and qualification(s) for your second internship site:',
	    	'filters' => array('StringTrim'),
	    	'validators'=>array($longTextLenValid),
	    	'required' => True,
			)
		);
		
		$this->addElement('text','resume',array(
	    	'label' => 'Link to resume PDF/DOC. File must be hosted externally (ie. on Google Docs):',
	    	'filters' => array('StringTrim'),
	    	'validators'=>array($longTextLenValid),
	    	'required' => True,
			)
		);

		$this->addElement('checkbox','usowo',array(
	    	'label' => 'I understand that the selection of Faculty Mentor who can award 3 hours of fall academic credit is required:',
	    	'multiOptions' => array('y'=>'Yes'),
	   		'separator'=>'',
	    	'required' => True,
	    	)
		);

		$this->addElement('checkbox','uenroll',array(
	    	'label' => 'I understand that the completion of Independent Study with selected Faculty Advisor is required:',
	    	'multiOptions' => array('y'=>'Yes'),
	    	'required' => True,
	    	)
		);
		
		$this->addElement('submit','submit',array(
	 	   'label' => 'Submit Application')
		);
		
		$this->addElement('hidden','uhours',array(
			    	'label' => 'I understand that I will have to complete 320 internship hours:',
			    	'multiOptions' => array('y'=>'Yes'),
			   		'separator'=>'',
			   		'value' => 'y',
			    	'required' => True,
		)
		);
	}
	
	private function getPositions(){
		$internmodel = new Application_Model_InternshipQuery();
		$dbtOrgs = new Application_Model_DbTable_Organizations();
		$internships = $internmodel->getInternships_Student();
		$positionOptionsArray = array();
		foreach($internships as $i){
			$org = $dbtOrgs->getOrganization('ID = '.$i['CPID']);
			$orgname = $org['NAME'];
			$positionOptionsArray[$i['POSID']]=$orgname."-".$i['NAME'];
		}	
		return $positionOptionsArray;
	}

}
?>
